﻿<%@ WebHandler Language="C#" Class="GetContactsHandler" %>

using System;
using System.Web;
using System.Text;
using System.Collections.Generic;

using Cisoft.Cisoft3G.BLL;
using Cisoft.Cisoft3G.Model;

public class GetContactsHandler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        
        
        if (context.Request["ContactGroupID"] != null)
        {
            ContactsBO bll = new ContactsBO();
            StringBuilder sb = new StringBuilder();
            List<ContactsMO> list = new List<ContactsMO>();
            list = bll.GetModelList(" CG_ContactGroupID_FK = " + context.Request.QueryString["ContactGroupID"].ToString());

            if (list.Count > 0)
            {
                foreach (ContactsMO model in list)
                {
                    sb.Append("<option value='" + model.CT_Mobile + "'>" + model.CT_Name + "(" + model.CT_Mobile + ")</option>");
                }
            }
            context.Response.Write(sb.ToString());
        }
        if (context.Request["SearchType"] != null && !string.IsNullOrEmpty(context.Request["SearchType"].ToString()) && context.Request["Condition"] != null && !string.IsNullOrEmpty(context.Request["Condition"].ToString()))
        {
            ContactsBO bll = new ContactsBO();
            StringBuilder sb = new StringBuilder();
            List<ContactsMO> list = new List<ContactsMO>();
            list = bll.GetModelList(" " + context.Request["SearchType"].ToString() + " like '%" + context.Request["Condition"].ToString() + "%' ");

            if (list.Count > 0)
            {
                foreach (ContactsMO model in list)
                {
                    sb.Append("<option value='" + model.CT_Mobile + "'>" + model.CT_Name + "(" + model.CT_Mobile + ")</option>");
                }
            }
            context.Response.Write(sb.ToString());
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}